function [imax,max,list,maxarray] = findMaximumPrincipalStress(elements)
ne = size(elements,2);
max = 0;
imax = 0;
cnt = 0;
list = [];
for i=1:ne
    if elements(i).isActivated==1
        sigma = elements(i).stress;
        %         if size(sigma,2) == 1
        %             p = spectralDecomposition(sigma);
        %             maxarray(i) = p(1);
        %             if p(1)>max
        %                 max = p(1);
        %                 imax = i;
        %             end
        %             if p(1) >= elements(i).ft
        %                 cnt = cnt+1;
        %                 list(cnt) = i;
        %                 value(cnt) = p(1);
        %             end
        %         else
        ng = size(sigma,2);
        for j = 1:ng
            p = spectralDecomposition(sigma(:,j));
            maxarray(i) = p(1);
            if p(1)>max
                max = p(1);
                imax = i;
            end
            if p(1) >= elements(i).ft
                cnt = cnt+1;
                list(cnt) = i;
                value(cnt) = p(1);
            end
        end
        %         end
    end
end
disp(['maximum sigma 1 = ' num2str(max) ...
    ' at element ' num2str(imax)]);
if cnt > 0
    disp([num2str(size(list(:),1)) ...
        ' elements got sigma1 > ft: ' num2str(list) ...
        ', ' num2str(value)]);
end
end
